/**

给你一棵二叉树，请你返回层数最深的叶子节点的和。



 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    void travel_Pre(TreeNode* node,int currDepth,int& maxDepth,int& sum)
    {
        if(node == 0)
            return ;

        if(node->left == 0 && node->right == 0)
        {
            if(currDepth > maxDepth)
            {
                maxDepth = currDepth;
                sum = node->val;
            }
            else if(currDepth == maxDepth)
            {
                //maxDepth = currDepth;
                sum += node->val;
            }
        }
        maxDepth = currDepth>maxDepth ? currDepth:maxDepth;

        travel_Pre(node->left, currDepth+1,maxDepth,sum);
        travel_Pre(node->right,currDepth+1,maxDepth,sum);

    }
    int deepestLeavesSum(TreeNode* root) {
        int maxDepth = -1;
        int sum = 0;
        travel_Pre( root, 0, maxDepth, sum);
        return sum;
    }
};